package com.lonty.intelligence.controller;

import com.lonty.intelligence.api.Result;
import com.lonty.intelligence.api.ResultCode;
import com.lonty.intelligence.model.HouseholdManagement;
import com.lonty.intelligence.service.HouseholdManagementService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Author 陈璇
 * @Date 2020/4/23 9:50
 * @Version 1.0
 */
@RestController
@RequestMapping("app/householdManagement")
@Validated
@Api(tags = "住户管理接口", produces = "application/json")
public class HouseholdManagementController {

    @Resource
    private HouseholdManagementService householdManagementService;

    @ApiOperation(value = "保存住户管理", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "telephone", value = "手机号",dataType = "string", paramType = "query", required = true)
    })
    @PostMapping("saveHouseholdManagement")
    public Result saveHouseholdManagement(String telephone){
        HouseholdManagement householdManagement = householdManagementService.saveHouseholdManagement(telephone);
        if(householdManagement != null){
            return Result.builder().data(householdManagement).build();
        }
        return Result.builder(ResultCode.OPERATION_ERROR).build();
    }

    @ApiOperation(value = "住户管理登录", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "phone", value = "手机号",dataType = "string", paramType = "query", required = true),
            @ApiImplicitParam(name = "code", value = "验证码",dataType = "string", paramType = "query", required = true),
            @ApiImplicitParam(name = "password", value = "密码",dataType = "string", paramType = "query", required = true)
    })
    @PostMapping("login")
    public Result login(String phone, String code, String password){
        return householdManagementService.login(phone, code, password);
    }

}
